package com.situ.day2;

import org.junit.Test;

public class ArrayDemo {
    @Test
    public void test1() {
        int num = 3;
        double[] array1 = new double[4];
        int[] array = new int[4];
        // 1、存放整数类型的数组
        // 2、长度是4
        // 3、只能存放int类型
        array[0] = 23;
        array[1] = 3;
        array[2] = 4;
        array[3] = 24;
        // .length 返回数组的长度
        System.out.println(array.length);// 4
//        for (int i = 0; i <= array.length - 1 ; i++) {
//            System.out.println(i);
//        }
        // i < array.length 代表i取不到array.length但是能取到array.length-1
        for (int i = 0; i < array.length; i++) {
            // System.out.println(i);
            System.out.println(array[i]);
        }
        System.out.println("-----------");
        // array.fori
        for (int i = array.length - 1; i >= 0; i--) {
            System.out.println(array[i]);
        }
    }

    @Test
    public void test2() {
        int[] array = new int[4];
        array[0] = 23;
        array[1] = 3;
        array[2] = 224;
        array[3] = 24;
        int max = array[0];// 假设第一个是最大值
        for (int i = 0; i < array.length; i++) {
            if (max < array[i]) { // 假设的最大值小于正在遍历的这个元素
                max = array[i];
            }
        }
        System.out.println("max: " + max);
    }

    @Test
    public void test55() {
        int[] array1 = {32,5,7,87};
        int[] array2 = new int[]{32,5,7,87};
        System.out.println(array2.length);
    }

    @Test
    public void test66() {
        int[] array = new int[4];
        array[0] = 23;
        array[1] = 3;
        array[2] = 224;
        array[3] = 24;
        for (int i = 0; i <= array.length; i++) {
            System.out.println(array[i]);
        }
    }

    @Test
    public void testBubble() {
        int[] array = {40, 17, 21, 1};
        for (int i = 1; i <= array.length - 1; i++) {
            for (int j = 0; j < array.length - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }

        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }
}
